package com.experienceBaby.Cashbook.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.experienceBaby.Cashbook.R;
import com.experienceBaby.Cashbook.bean.Ranking;
import com.experienceBaby.Cashbook.bean.RankingList;

import java.text.DecimalFormat;
import java.util.List;
import java.util.zip.Inflater;

import de.hdodenhof.circleimageview.CircleImageView;

public class MyListviewAdapter extends BaseAdapter {
    Context context;
    List<RankingList> list;
    final LayoutInflater mInflater;


    public MyListviewAdapter(Context context, List<RankingList> list) {
        this.context = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = mInflater.inflate(R.layout.listview_fragment_chart, null);
        CircleImageView lfc_iv1 = convertView.findViewById(R.id.lfc_iv1);
        TextView lfc_tv2_1 = convertView.findViewById(R.id.lfc_tv2_1);
        TextView lfc_tv2_2 = convertView.findViewById(R.id.lfc_tv2_2);
        TextView lfc_tv2_3 = convertView.findViewById(R.id.lfc_tv2_3);
        lfc_tv2_1.setText(list.get(position).getType());
        DecimalFormat df = new DecimalFormat("0.0%");
        lfc_tv2_2.setText(df.format(list.get(position).getPercentage()));
        lfc_tv2_3.setText(String.format("%.2f", list.get(position).getCost()));
        return convertView;
    }
}
